/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-09-21
 * Time: 17:44
 */
public class StringBuilderDemo {
    public static void main(String[] args) {
        //String转换成StringBuilder
        //方法1
        StringBuilder sb = new StringBuilder("abc");
        System.out.println(sb);
        //方法2
        StringBuilder sb1 = new StringBuilder();
        sb1.append("abc");
        sb1.append("123");
        sb1.append("567");
        System.out.println(sb1);

        //StringBuilder转换成String
        String str = sb1.toString();
        System.out.println(str);

    }
    public static void main2(String[] args) {
        //1.创建对象
        StringBuilder sb = new StringBuilder();

        //2.添加字符串
        sb.append("aaa");
        sb.append("bbb");
        sb.append("ccc");
        sb.append("ddd");
        System.out.println(sb);

        //3.把StringBuilder变回String
        String str = sb.toString();
        System.out.println(str);

    }
    public static void main1(String[] args) {
        //创建对象
        StringBuilder sb = new StringBuilder("abc");

        //1.添加元素
        sb.append(1);
        sb.append(2.3);
        sb.append(false);

        System.out.println(sb);

        //2.反转
        sb.reverse();
        //打印
        //因为StringBuilder是java已经写好的类，java底层做了特殊处理，打印对象不是地址值，是属性值
        System.out.println(sb);

        //3.获取长度
        int len = sb.length();
        System.out.println(len);



    }
}
